<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>SB Admin - Login</title>

    <!-- Custom fonts for this template-->
    <link href="/public/Admin/vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">

    <!-- Custom styles for this template-->
    <link href="/public/Admin/css/sb-admin.css" rel="stylesheet">

</head>

<body class="bg-dark">

    <div style="position: absolute;width:400px;height:200px;left:50%;top:40%; 
  margin-left:-200px;margin-top:-100px;" class="container">
        <div class="card card-login mx-auto mt-5">
            <div class="card-header">Login</div>
            <div class="card-body">
                <div class="form-group">
                    <div class="form-label-group">
                        <input type="email" id="userName" class="form-control" placeholder="userName"
                            required="required" autofocus="autofocus">
                        <label for="userName">userName</label>
                    </div>
                </div>
                <div class="form-group">
                    <div class="form-label-group">
                        <input type="password" id="inputPassword" class="form-control" placeholder="Password"
                            required="required">
                        <label for="inputPassword">Password</label>
                    </div>
                </div>
                <div class="form-group">
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" value="remember-me">
                            记住我
                        </label>
                    </div>
                </div>
                <a class="btn btn-primary btn-block" onclick="post()">登陆</a>
            </div>
        </div>
    </div>

    <!-- Bootstrap core JavaScript-->
    <script src="/public/Admin/vendor/jquery/jquery.min.js"></script>
    <script src="/public/Admin/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="/public/Admin/vendor/jquery-easing/jquery.easing.min.js"></script>
    <script>
        function post() {
            $.ajax({
                type: "POST",
                url: "{:url('admin/home/index')}",
                data: {
                    user_name: $('#userName').val(),
                    password: $('#inputPassword').val(),
                },
                dataType: "JSON",
                success: function (response) {
                    if (response.code) {
                    window.location.href = "{:url('admin/home/index')}";
                    }else{
                        alert('密码错误');
                    }
                }
            });
        }
    </script>
</body>

</html>